﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace XFGameFramework
{
    public class QuaternionExtensions : MonoBehaviour
    {

        public static float InverseLerp(Quaternion from, Quaternion to, Quaternion current)
        {
            float lerp = Mathf.InverseLerp(from.x, to.x, current.x);

            if (lerp > 0 && lerp <= 1)
            {
                if (Quaternion.Angle(current, Quaternion.Lerp(from, to, lerp)) <= 1)
                    return lerp;
            }

            lerp = Mathf.InverseLerp(from.y, to.y, current.y);

            if (lerp > 0 && lerp <= 1)
            {
                if (Quaternion.Angle(current, Quaternion.Lerp(from, to, lerp)) <= 1)
                    return lerp;
            }

            lerp = Mathf.InverseLerp(from.z, to.z, current.z);

            if (lerp > 0 && lerp <= 1)
            {
                if (Quaternion.Angle(current, Quaternion.Lerp(from, to, lerp)) <= 1)
                    return lerp;
            } 
            return 0;
        }

    }

}

